package com.future.common.utils;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;

import com.future.common.exception.BadRequestException;

public class ValidationUtil {
	private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
	public static void checkValidation(Object object){
		Set<ConstraintViolation<Object>> set = validator.validate(object);
        // 校验错误信息返回
		if(set.size()>0){
			ConstraintViolation<Object> constraintViolations  = set.stream().findFirst().get();
			throw new BadRequestException(constraintViolations.getMessage());
		}
        
	}
}	
